package cn.fintecher.pangolin.service.repair.model.request;

import cn.fintecher.pangolin.common.web.SearchRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.util.Objects;

import static org.elasticsearch.index.query.QueryBuilders.wildcardQuery;

@Data
public class KosekiDataSearchRequest extends SearchRequest {
    @ApiModelProperty(notes = "姓名")
    private String name;

    @ApiModelProperty("身份证号")
    private String idNo;

    @ApiModelProperty("申调地区")
    private String applyTransferArea;

    @ApiModelProperty("户籍")
    private String koseki;


    @Override
    public QueryBuilder generateQueryBuilder() {
        BoolQueryBuilder qb = QueryBuilders
                .boolQuery();
        if (Objects.nonNull(this.name)) {
            qb.must(wildcardQuery("name.keyword", StringUtils.join("*",this.name,"*")));
        }
        if (Objects.nonNull(this.idNo)) {
            qb.must(wildcardQuery("idNo.keyword", StringUtils.join("*",this.idNo,"*")));
        }
        if (Objects.nonNull(this.applyTransferArea)) {
            qb.must(wildcardQuery("applyTransferArea.keyword", StringUtils.join("*",this.applyTransferArea,"*")));
        }
        if (Objects.nonNull(this.koseki)) {
            qb.must(wildcardQuery("koseki.keyword", StringUtils.join("*",this.koseki,"*")));
        }
        return qb;
    }
}
